package com.ycfmedical.bed.adapter;

import com.bilibili.magicasakura.widgets.TintImageView;
import com.ycfmedical.bed.R;
import com.ycfmedical.bed.bean.EntertainItem;
import com.zhy.autolayout.utils.AutoUtils;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.BindView;
import cn.droidlover.xdroidmvp.base.SimpleRecAdapter;
import cn.droidlover.xdroidmvp.kit.KnifeKit;

/**
 * Created by Egoist on 2017/1/19.
 */

public class MusicListAdapter extends SimpleRecAdapter<EntertainItem, MusicListAdapter.ViewHolder>
{
    public static final int TAG_MORE_BUTTON = 1;
    public static final int TAG_ITEM = 2;

    public MusicListAdapter(Context context)
    {
        super(context);
    }

    @Override
    public ViewHolder newViewHolder(View itemView)
    {
        return new ViewHolder(itemView);
    }
    
    @Override
    public int getLayoutId()
    {
        return R.layout.layout_item_musicinfo;
    }
    
    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position)
    {
        final EntertainItem item = data.get(position);
        holder.topText.setText(item.getName());
        holder.bottomText.setText(item.getArtist());
        holder.moreButton.setOnClickListener((View v) -> {
            if (getRecItemClick() != null)
            {
                getRecItemClick().onItemClick(position, item, TAG_MORE_BUTTON, holder);
            }
            
        });
        
        holder.itemView.setOnClickListener((View v) -> {
            if (getRecItemClick() != null)
            {
                getRecItemClick().onItemClick(position, item, TAG_ITEM, holder);
            }
        });
    }

    
    public static class ViewHolder extends RecyclerView.ViewHolder
    {
        @BindView(R.id.play_state)
        TintImageView playState;

        @BindView(R.id.viewpager_list_toptext)
        TextView topText;

        @BindView(R.id.viewpager_list_bottom_text)
        TextView bottomText;

        @BindView(R.id.musiclist_more_button)
        ImageView moreButton;
        
        public ViewHolder(View itemView)
        {
            super(itemView);
            KnifeKit.bind(this, itemView);
            AutoUtils.autoSize(itemView);
        }
    }
}
